package com.shuogesha.platform.feign;

import static com.shuogesha.common.web.mongo.SimplePage.cpn;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.shuogesha.common.util.JsonResult;
import com.shuogesha.platform.client.RoleFeignClient;
import com.shuogesha.platform.entity.Menu;
import com.shuogesha.platform.entity.Role;

@RestController
@RequestMapping("/api/role/")
public class RoleFeignAct {
	@RequestMapping(value = "/list")
	public Object v_list(String name, Integer pageNo, Integer pageSize) throws UnsupportedEncodingException {
		return roleFeignClient.list(name, cpn(pageNo), pageSize);
	}

	@RequestMapping(value = "/get")
	public Object v_get(Long id) {
		return roleFeignClient.get(id);
	}

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public Object o_save(@RequestBody Role bean) {

		return roleFeignClient.save(bean);
	}

	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public Object o_update(@RequestBody Role bean) {
		return roleFeignClient.update(bean);
	}

	@RequestMapping(value = "/delete")
	public Object o_delete(Long[] ids) {
		return roleFeignClient.delete(ids);
	}

	@Autowired
	public RoleFeignClient roleFeignClient;
	
	@RequestMapping(value = "/saveRoleMenus", method = RequestMethod.POST)
	public JsonResult<Role> saveRoleMenus(@RequestBody Role bean){
		return roleFeignClient.saveRoleMenus(bean);
	}
	 
	@RequestMapping(value = "/getAllMenusByUser")
	public JsonResult<List<Menu>> getAllMenusByUser(@RequestParam("userId") Long userId, @RequestParam("type") Integer type){
		return roleFeignClient.getAllMenusByUser(userId, type);
	}
	 
	@RequestMapping(value = "/getAllPermsByUser")
	public JsonResult<Set<String> > getAllPermsByUser(@RequestParam("userId") Long userId){
		return roleFeignClient.getAllPermsByUser(userId);
	}
	
	@RequestMapping(value = "/getAllRole")
	public JsonResult<List<Role>> getAllRole(){
		return roleFeignClient.getAllRole();
	}
}
